package www.game.findodd;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class FindOdd {
    public static int findIt(int[] a) {
        Map<Integer, List<Integer>> collect = Arrays.stream(a).sorted()
            .mapToObj(item -> item)
            .collect(Collectors.groupingBy(Function.identity()));
        for (Map.Entry<Integer, List<Integer>> entry : collect.entrySet()) {
            if ((entry.getValue().size() & 1) == 1) {
                return entry.getKey();
            }
        }
        return 0;
    }

}